package cn.pwrd.custom.util;

import android.text.TextUtils;
import android.util.Log;

@SuppressWarnings("unused")
public class LogUtils {
	private static boolean VERBOSE = true;
	private static boolean ERROR = true;
	private static boolean INFO = true;
	private static boolean WARN = true;
	private static boolean DEBUG = false;

	public static void setDebug(boolean open) {
		DEBUG = open;
	}

	public static void setInfo(boolean open) {
		INFO = open;
	}

	public static void setError(boolean open) {
		ERROR = open;
	}

	public static void setWarn(boolean open) {
		WARN = open;
	}

	public static void setVerbose(boolean open) {
		VERBOSE = open;
	}

	public static void v(String tag, String message) {
		if (VERBOSE) {
			Log.v(tag, message);
		}

	}

	public static void d(String tag, String message) {
		if (DEBUG) {
			Log.d(tag, message);
		}

	}

	public static void e(String tag, String message) {
		if (ERROR) {
			Log.e(tag, message);
		}

	}

	public static void i(String tag, String message) {
		if (INFO) {
			Log.i(tag, message);
		}

	}

	public static void w(String tag, String message) {
		if (WARN) {
			Log.w(tag, message);
		}
	}

	public static void v(String tag, Throwable ex) {
		if (VERBOSE) {
			Log.v(tag, basciExceptionMsg(ex), ex);
		}

	}

	public static void d(String tag, Throwable ex) {
		if (DEBUG) {
			Log.d(tag, basciExceptionMsg(ex), ex);
		}

	}

	public static void e(String tag, Throwable ex) {
		if (ERROR) {
			Log.e(tag, basciExceptionMsg(ex), ex);
		}

	}

	public static void i(String tag, Throwable ex) {
		if (INFO) {
			Log.i(tag, basciExceptionMsg(ex), ex);
		}

	}

	public static void w(String tag, Throwable ex) {
		if (WARN) {
			Log.w(tag, basciExceptionMsg(ex), ex);
		}
	}

	public static String basciExceptionMsg(Throwable e) {
		if (e == null) {
			return "null exception";
		}
		return TextUtils.isEmpty(e.getLocalizedMessage()) ? e.toString() : e.getLocalizedMessage();
	}
}
